﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;

namespace HA.ModFlow.Domain.DomainLayer
{
[Serializable]
    public class StressPeriodCollection
    {
        public StressPeriodCollection()
        {
            _innerList = new List<StressPeriod>();

            
        }




        #region 事件模型

       

         [field: NonSerialized]

         public event EventHandler<StressPeriodChangedEventArgs> StressPeriodChanged;

        #endregion



     

        List<StressPeriod> _innerList;


        public List<StressPeriod> InnerList
        {
            get { return _innerList; }
          
        }


        #region 对外公共接口部分

        /// <summary>
        /// 是否含有瞬时非稳定流模型
        /// </summary>
        public bool IsHaveTransient
        {
            get {

                foreach (StressPeriod item in this._innerList)
                {
                    if (item.IsSteadyState==false)
                    {

                        return true;
                    }
                    
                }

                return false;
            }
        }

        ///<summary>
        ///添加应力期
        ///</summary>
        public void AddStressPeriod(StressPeriod sp)
        {
            this._innerList.Add(sp);

            if (this.StressPeriodChanged != null)
            {
                StressPeriodChanged(this,new StressPeriodChangedEventArgs(this._innerList));

            }
        }



    /// <summary>
    /// 主要用于窗体里整个改变应力期的设置
    /// 现在方案是：1、是否是瞬态应力期变化，通过事件变化内部数据
    /// 2、应力期与修改之前的应力期条数是否相同，如果不同则通过事件变化内部数据
    /// </summary>
    /// <param name="lst"></param>
        public void ResetStressPeriods(List<StressPeriod> lst,bool isForEvent = false)
        {
            bool isChange = false;//默认没有变化 
            if (!isForEvent)
            {
                if (this._innerList.Count != lst.Count)
                {
                    isChange = true;
                }
                else
                {
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (this._innerList[i].IsSteadyState != lst[i].IsSteadyState)
                        {
                            isChange = true;
                            break;
                        }
                    }
                }


                this._innerList.Clear();
                this._innerList.AddRange(lst);
            }

            if (isChange || isForEvent)
            {
                
                if (this.StressPeriodChanged != null)
                {
                    StressPeriodChanged(this, new StressPeriodChangedEventArgs(lst));
                }
            }
        }




        #endregion






    }
}
